package top.heliming.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import top.heliming.bean.User;
import top.heliming.dao.UserMapper;
import top.heliming.service.UserService;

/**
 * description: //TODO
 *
 * @author: heliming
 * @date:2019/05/22 上午 1:48
 */
@Service
public class UserServiceImpl implements UserService {
  @Autowired
  private UserMapper userMapper;

  @Override
  public User queryById(Long id){
   return this.userMapper.selectByPrimaryKey(id);
  }

  @Override
  @Transactional
  public void deleteById(Long id){
   this.userMapper.deleteByPrimaryKey(id);

  }

 @Override
 public List<User> queryAll() {
  return userMapper.selectAll();
 }

  @Override
  public List<User> list(Integer startNo,Integer pageSize,String key) {
    return userMapper.list(startNo,pageSize,key);
  }

  @Override
  public Integer count(String key){
    User u = new User();
    if(!StringUtils.isEmpty(key)){
      u.setName(key);
    }
    return userMapper.selectCount(u);
  }
}
